/*    */ package com.qmsk.business.member.questionnaire.controller;
/*    */ 
/*    */ import com.qmsk.business.member.member.dao.MemberDAO;
/*    */ import com.qmsk.business.member.memberIntegralRule.service.MemberIntegralRuleService;
/*    */ import com.qmsk.business.member.questionnaire.dao.QuestionnaireDAO;
/*    */ import com.qmsk.business.member.questionnaire.dao.QuestionnaireProblemDAO;
/*    */ import com.qmsk.business.member.questionnaire.dao.ReturnAnswerDAO;
/*    */ import com.qmsk.business.member.questionnaire.dao.ReturnDAO;
/*    */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*    */ import com.utils.gson.in.GsonHeadManyRows;
/*    */ import com.utils.gson.in.GsonHeadOneRow;
/*    */ import com.utils.gson.out.GsonEbRst;
/*    */ import com.utils.jdbc.connection.DbConnection;
/*    */ import com.utils.web.RequestUtils;
/*    */ import com.utils.web.ResponseUtils;
/*    */ import java.util.Date;
/*    */ import java.util.Map;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.apache.commons.lang.StringUtils;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.PathVariable;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ 
/*    */ @Controller
/*    */ @RequestMapping({"questionnaire"})
/*    */ public class QuestionnaireController
/*    */ {
/* 35 */   Logger logger = Logger.getLogger(QuestionnaireController.class);
/*    */ 
/*    */   @Autowired
/*    */   private QuestionnaireProblemDAO questionnaireProblemDAO;
/*    */ 
/*    */   @Autowired
/*    */   private QuestionnaireDAO dao;
/*    */ 
/*    */   @Autowired
/*    */   private ReturnAnswerDAO returnAnswerDAO;
/*    */ 
/*    */   @Autowired
/*    */   private ReturnDAO returnDAO;
/*    */ 
/*    */   @Autowired
/*    */   private MemberDAO memberDAO;
/*    */ 
/*    */   @Autowired
/*    */   private MemberIntegralRuleService integralRuleService;
/*    */ 
/*    */   @RequestMapping(value={"/currentId"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*    */   public void getProblemList(HttpServletRequest request, HttpServletResponse response)
/*    */   {
/*    */     try {
/* 59 */       Long quesionId = this.dao.getCurrentQuestionId();
/*    */ 
/* 61 */       if (quesionId == null) {
/* 62 */         ResponseUtils.toGsonEbRst(new String[] { "questionId" }, 
/* 63 */           new Object[] { "" }, response);
/* 64 */         return; }
/* 65 */       ResponseUtils.toGsonEbRst(new String[] { "questionId" }, 
/* 66 */         new Object[] { quesionId }, response);
/*    */     }
/*    */     catch (Exception e)
/*    */     {
/* 70 */       this.logger.error(e);
/* 71 */       ResponseUtils.setErrorMsgResponse(
/* 72 */         RequestUtils.getFindDataErrorMessage(request), response);
/*    */     }
/*    */   }
/*    */ 
/*    */   @RequestMapping(value={"/page/{questionnaireId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*    */   public void getProblemList(HttpServletRequest request, HttpServletResponse response, @PathVariable("questionnaireId") Long questionnaireId)
/*    */   {
/*    */     try
/*    */     {
/* 81 */       GsonEbRst rst = this.questionnaireProblemDAO
/* 82 */         .getQuestionnairePage(questionnaireId);
/* 83 */       ResponseUtils.setResponseResult(rst, response);
/*    */     } catch (Exception e) {
/* 85 */       this.logger.error(e);
/* 86 */       ResponseUtils.setErrorMsgResponse(
/* 87 */         RequestUtils.getFindDataErrorMessage(request), response);
/*    */     }
/*    */   }
/*    */ 
/*    */   @RequestMapping(value={"/submit/{questionnaireId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*    */   public void subReturn(HttpServletRequest request, HttpServletResponse response, @PathVariable("questionnaireId") Long questionnaireId)
/*    */   {
/*    */     try
/*    */     {
/* 98 */       String name = RequestUtils.getString(request, "name");
/* 99 */       String tel = RequestUtils.getString(request, "tel");
/* 100 */       String openId = RequestUtils.getString(request, "openId");
/* 101 */       Long shopId = RequestUtils.getLong(request, "shopId");
/*    */ 
/* 103 */       if (StringUtils.isEmpty(name)) {
/* 104 */         ResponseUtils.setErrorMsgResponse("姓名不能为空！", response);
/* 105 */         return;
/*    */       }
/*    */ 
/* 108 */       if (shopId == null) {
/* 109 */         ResponseUtils.setErrorMsgResponse("店面不能为空！", response);
/* 110 */         return;
/*    */       }
/*    */ 
/* 113 */       if (StringUtils.isEmpty(tel)) {
/* 114 */         ResponseUtils.setErrorMsgResponse("电话不能为空！", response);
/* 115 */         return;
/*    */       }
/*    */ 
/* 118 */       if (tel.trim().length() != 11) {
/* 119 */         ResponseUtils.setErrorMsgResponse("电话长度必须为11位！", response);
/* 120 */         return;
/*    */       }
/*    */ 
/* 125 */       if (this.returnDAO.checkReturnUnique(questionnaireId, tel)) {
/* 126 */         ResponseUtils.setErrorMsgResponse("您已经提交过该调查问卷！", response);
/* 127 */         return;
/*    */       }
/*    */ 
/* 131 */       if ((StringUtils.isNotEmpty(openId)) && 
/* 132 */         (this.returnDAO.checkSubmitUnique(openId, questionnaireId))) {
/* 133 */         ResponseUtils.setErrorMsgResponse("您已经提交过该调查问卷！", response);
/* 134 */         return;
/*    */       }
/*    */ 
/* 138 */       String[] head = { "questionnaireId", "createFileTime", 
/* 139 */         "customerName", "mp", "openId" };
/*    */ 
/* 141 */       Object[] list = { questionnaireId, new Date(), name, 
/* 142 */         tel, openId };
/* 143 */       GsonHeadOneRow row = new GsonHeadOneRow(head, list);
/* 144 */       int n = this.returnDAO.insertGsonHeadOneRow(row);
/*    */ 
/* 146 */       if (n <= 0) {
/* 147 */         ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 148 */         DbConnection.rollback();
/* 149 */         return;
/*    */       }
/*    */ 
/* 152 */       Long returnId = this.returnDAO.getLastId();
/*    */ 
/* 154 */       if (returnId == null) {
/* 155 */         ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 156 */         DbConnection.rollback();
/* 157 */         return;
/*    */       }
/*    */ 
/* 160 */       GsonHeadManyRows rows = this.questionnaireProblemDAO
/* 161 */         .getProblemIdList(questionnaireId);
/*    */ 
/* 163 */       head = new String[] { "returnId", "problemId", "answer" };
/* 164 */       for (int i = 0; i < rows.getDataLength(); ++i) {
/* 165 */         String problemId = (String)rows.getValueOfName("problemId", i);
/* 166 */         Integer type = (Integer)rows.getValueOfName("type", i);
/* 167 */         if ((type.intValue() == 1) || (type.intValue() == 3)) {
/* 168 */           Long answerId = RequestUtils.getLong(request, 
/* 169 */             problemId);
/* 170 */           list = new Object[] { returnId, problemId, answerId };
/*    */ 
/* 172 */           row = new GsonHeadOneRow(head, list);
/* 173 */           n = this.returnAnswerDAO.insertGsonHeadOneRow(row);
/* 174 */           if (n <= 0) {
/* 175 */             ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 176 */             DbConnection.rollback();
/* 177 */             label666: label560: return;
/*    */           }
/* 179 */         } else if (type.intValue() == 2) {
/* 180 */           String str = request.getParameter(problemId);
/* 181 */           String[] answers = null;
/* 182 */           if (str != null) {
/* 183 */             answers = str.split("[ ]*,[ ]*");
/*    */           }
/* 185 */           int j = 0; 
/*    */           do { String answer = answers[j];
/* 187 */             list = new Object[] { returnId, problemId, answer };
/*    */ 
/* 189 */             row = new GsonHeadOneRow(head, list);
/* 190 */             n = this.returnAnswerDAO.insertGsonHeadOneRow(row);
/* 191 */             if (n <= 0)
/*    */             {
/* 193 */               ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 194 */               DbConnection.rollback();
/* 195 */               return;
/*    */             }
/* 185 */             ++j; if (answers == null) break ;  }
/* 185 */           while (j < answers.length);
/*    */         }
/* 200 */         else if (type.intValue() == 4) {
/* 201 */           String answer = RequestUtils.getString(request, 
/* 202 */             problemId);
/* 203 */           list = new Object[] { returnId, problemId, answer };
/* 204 */           row = new GsonHeadOneRow(head, list);
/* 205 */           n = this.returnAnswerDAO.insertGsonHeadOneRow(row);
/* 206 */           if (n <= 0) {
/* 207 */             ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 208 */             DbConnection.rollback();
/* 209 */             return;
/*    */           }
/*    */         }
/*    */       }
/*    */ 
/* 214 */       if (StringUtils.isEmpty(openId)) {
/* 215 */         DbConnection.commit();
/* 216 */         ResponseUtils.setSuccessResponse(response);
/* 217 */         return;
/*    */       }
/*    */ 
/* 222 */       Long memberId = this.memberDAO.getMemberIdOfOpenId(openId, shopId);
/* 223 */       if (memberId == null) {
/* 224 */         DbConnection.commit();
/* 225 */         return;
/*    */       }
/*    */ 
/* 228 */       this.logger.info("OpenId:" + openId);
/* 229 */       Map params = this.integralRuleService
/* 230 */         .sendIntegralOfRuleName("调查问券", memberId, shopId);
/*    */ 
/* 232 */       String customerName = (String) params.get("customerName");
/* 233 */       Integer intAmt = (Integer)params.get("intAmt");
/* 234 */       if (intAmt.intValue() <= 0) {
/* 235 */         DbConnection.commit();
/* 236 */         ResponseUtils.setSuccessResponse(response);
/* 237 */         return;
/*    */       }
/* 239 */       String str = "尊敬的 " + customerName + " ，感谢您参与调查，本次获得 " + intAmt + 
/* 240 */         " 积分！";
/* 241 */       this.logger.info("Send Message:" + str);
/* 242 */       WeiXinUtil.sendTextMessageOfMain(str, openId);
/* 243 */       ResponseUtils.setSuccessResponse(response);
/* 244 */       DbConnection.commit();
/*    */     } catch (Exception e) {
/* 246 */       e.printStackTrace();
/* 247 */       DbConnection.rollback();
/* 248 */       this.logger.error(e.getMessage());
/* 249 */       ResponseUtils.setErrorMsgResponse(
/* 250 */         RequestUtils.getFindDataErrorMessage(request), response);
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.member.questionnaire.controller.QuestionnaireController
 * JD-Core Version:    0.5.3
 */